<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../static/发布课程.css">
    <link rel="stylesheet" href="../static/iconfont/iconfont.css">
    <title>发布课程</title>
</head>
<body>
<div class="head">
    <div class="header">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;<img width=36 height=36 src="../static/xh.png"/><img width=180 height=36 src="../static/wz.png"/>
        <a href="/teacher/login" class="exit"><i class="iconfont icon-tuichu"></i>退出登录</a></div>
</div>
<div class="big_box">
    <div class="wrap">
        <div class="seg"></div>
        <div class="item_title">
            <b>教师端</b>
        </div>
        <div class = "seg"></div>
        <div class="item">
            <a href="http://localhost:8080/teacher/tutorial"><i class="iconfont icon-yixuan" ></i>&ensp;任教课程</a>
        </div>
        <div class="item">
            <a href="http://localhost:8080/teacher/up_course"><i class="iconfont icon-fabu" ></i>&ensp;发布课程</a>
        </div>
        <div class="item">
            <a href="http://localhost:8080/teacher/modify_course"><i class="iconfont icon-xiugai" ></i>&ensp;修改课程</a>
        </div>
        <div class="item">
            <a href="http://localhost:8080/teacher/delete_course"><i class="iconfont icon-shanchu" ></i>&ensp;删除课程</a>
        </div>
        <div class="item">
            <a href="个人信息_tc.html"><i class="iconfont icon-gerenxinxi" ></i>&ensp;个人信息</a>
        </div>
    </div>
    <div class="addcourse">
        <div class="row">
            <h1>新增课程</h1>
        </div>
        <div class="add">
            <form action="\addcourse" method="post">
                <tr>
                <td>课&ensp;程&ensp;号：<input id="id" type="text"/></td><br />
                <td>课&ensp;程&ensp;名：<input id="name" type="text"/></td><br />
                <td>课程学时：<input id="length" type="text"/></td><br />
                <td>课程学分：<input id="score" type="text"/></td><br />
                <td>上课时间：第<input id="week_f" class="time" type="text"/>周至第<input id="week_l" class="time"/>周</td>
                    <select id="day" class="day">
                        <option value="星期一">星期一</option>
                        <option value="星期二">星期二</option>
                        <option value="星期三">星期三</option>
                        <option value="星期四">星期四</option>
                        <option value="星期五">星期五</option>
                        <option value="星期六">星期六</option>
                        <option value="星期日">星期日</option>
                    </select>
                    <select id="jie" class="jie">
                        <option value="1-2节">1-2节</option>
                        <option value="3-4节">3-4节</option>
                        <option value="5-6节">5-6节</option>
                        <option value="7-8节">7-8节</option>
                        <option value="9-10节">9-10节</option>
                    </select>
                    <select id="term" class="jie">
                        <option value="1">大一上学期</option>
                        <option value="2">大一下学期</option>
                        <option value="3">大二上学期</option>
                        <option value="4">大二下学期</option>
                        <option value="5">大三上学期</option>
                        <option value="6">大三下学期</option>
                    </select>
                    <br />
                <td>上课地点：<input id="site" type="text"/></td><br />
                    <td>可选人数：<input id="number" type="text"/></td>
                    <td><form method="post"> 课程类别：
                        <input type="radio" id="r1" name="classification" value="公共课" checked="checked"/>公共课
                        <input type="radio" id="r2" name="classification" value="专业课"/>专业课
                        <input type="radio" id="r3" name="classification" value="通识课"/>通识课</form></td><br />
                    <button type="button" onclick="add0()">立即发布</button></td></tr>
            </form>
        </div>
    </div>
</div>
<div class="modal" id="myModal" style="display: none;">
    <div class="modal-dialog">
        <form class="modal-content" method="post" id="Form" role="form">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" onclick="Default()">
                    <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                </button>
            </div>
            <div class="modal-body">
                <h4 class="modal-title">确定发布<input placeholder="课程名" type="text" id="course_name" class="input" />这门课吗？</h4>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn_default" data-dismiss="modal" onclick="Default()">取消</button>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
                <button type="button" class="btn_default" data-dismiss="modal" onclick="add()">确定</button>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
            </div>
        </form>
    </div>
</div>
</div>
<script>
    function  Default() {
        document.getElementById("myModal").style.display="none";
    }
    function add0(){
        document.getElementById("myModal").style.display="block";
       // var cname=document.getElementById("name").value;
       var cname=$("#name").val();
       $("#course_name").attr("value",cname);
    }
    function add(){
        var classify;
        $("input[type='radio']").each(function(){
            var id=$(this).attr("id");
            console.log(id);
            console.log($("#"+id).prop("checked"));
            if($("#"+id).prop("checked")){
                console.log(id);
                classify=$("#"+id).val();
                console.log(classify);
            }
        });
        $.ajax({
            type:"post",
            url:'/teacher/uup_course',
            dataType:"json",
            data:{
                "cid":$("#id").val(),
                "cname":$("#name").val(),
                "clength":$("#length").val(),
                "cscore":$("#score").val(),
                "cweekf":$("#week_f").val(),
                "cweekl":$("#week_l").val(),
                "cday":$("#day").val(),
                "cjie":$("#jie").val(),
                "csite":$("#site").val(),
                "cnumber":$("#number").val(),
                "cterm":$("#term").val(),
                "classify":classify
            },
            success:function(dat){
                if(dat.stat==0){
                    alert("发布成功！");
                    window.location.reload();
                  //  document.getElementById("myModal").style.display="none";
                }
                else if(dat.stat==1){
                    alert("课程号重复，请重新输入！");
                    document.getElementById("myModal").style.display="none";
                }
                else{
                    alert("您已在该上课时间发布过课程，请重新输入上课时间");
                    document.getElementById("myModal").style.display="none";
                }
            },
            error : function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("错误");
                // 状态码
                console.log(XMLHttpRequest.status);
                // 状态
                console.log(XMLHttpRequest.readyState);
                // 错误信息
                console.log(textStatus);
            }
        })
    }
    function logout() {
        $.ajax({
            async:false,
            type:"post",
            url:'/logout',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
            dataType:"text",
            complete:function(){
                window.location.reload();
            }
        })

    }
</script>
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/dist/js/bootstrap.min.js"></script>
<!-- Just to make our placeholder images work. Don't actually copy the next line! -->
<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/assets/js/vendor/holder.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>